﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.SoldierArchives.BLL;
using Yipusoft.Account.BLL;

public partial class Police_TransferQurey2 : System.Web.UI.Page
{

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindAcceptCount();
        }
    }


    private void BindAcceptCount()
    {
        //具备接收统计权限
        if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "400104"))
        {
            gvTrasferStat.DataSource = Department.GetList("RIGHT(DepartmentID,2)='00'");
            gvTrasferStat.DataBind();
        }
        else
        {
            //具备本级调动权限
            if (Yipusoft.Account.BLL.User.HasPermission(User.Identity.Name, "400103"))
            {
                gvTrasferStat.DataSource = Department.GetList("DepartmentID='" + Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID.Substring(0, 4) + "000'");
                gvTrasferStat.DataBind();
            }
            else
            {
                Response.Write("<script>alert('没有权限！');history.back(0);</script>");

            }
        }
    }
    protected void gvTrasferStat_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            // Display the company name in italics.
            int count = TransferSoldier.NeedAcceptedCount(gvTrasferStat.DataKeys[e.Row.RowIndex].Value.ToString());
            if (count > 0)
            {
                e.Row.Cells[2].Text = "<a href='TransferList.aspx?DepartmentID=" + gvTrasferStat.DataKeys[e.Row.RowIndex].Value.ToString() + "'>" + count.ToString() + "</a>";
            }
            else
            {
                e.Row.Cells[2].Text = count.ToString();
            }

            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = (gvTrasferStat.PageIndex * gvTrasferStat.PageSize + e.Row.RowIndex + 1).ToString();
            ////当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }


    }

    
    protected void gvTrasferStat_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        string departmentID = gvTrasferStat.DataKeys[e.NewSelectedIndex].Value.ToString();
        if (TransferSoldier.AcceptTransfer(departmentID, Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).UserName, User.Identity.Name, DateTime.Now))
        {
            BindAcceptCount();
          
        }
    }

  
}
